package com.hua.controller;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.hua.config.oss.OssProperties;
import com.hua.entity.Entry;
import com.hua.service.FileService;
import com.hua.utils.Result;
import org.joda.time.DateTime;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;

@RestController
@ResponseBody
@RequestMapping("/api/oss/file")
public class OSSController {
    @Resource
    private FileService fileService;
    @Resource
    private OssProperties ossProperties;


    @PostMapping("/upload")
    public Result upload(MultipartFile file, String module){
        //返回上传到oss的路径
        String url = fileService.upload(file,module);
        return Result.ok(url).message("文件上传成功");
    }

    @PostMapping("/uploadImg")
    public Result uploadImg(MultipartFile file, String module) {
        //返回上传到oss的路径
        String url = fileService.uploadImg(file, module);
        System.out.println(url);
        return Result.ok(url).message("文件上传成功");
    }
}
